package com.ems.sys.controller;

import com.ems.sys.pojo.EmsMood;
import com.ems.sys.service.EmsMoodService;
import com.github.pagehelper.PageInfo;
import com.ems.entity.Result;
import com.ems.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/sys/emsMood")
//@CrossOrigin
public class EmsMoodController {

    @Autowired
    private EmsMoodService emsMoodService;

    /***
     * EmsMood分页条件搜索实现
     * @param emsMood
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  EmsMood emsMood, @PathVariable  int page, @PathVariable  int size){
        //调用EmsMoodService实现分页条件查询EmsMood
        PageInfo<EmsMood> pageInfo = emsMoodService.findPage(emsMood, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * EmsMood分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用EmsMoodService实现分页查询EmsMood
        PageInfo<EmsMood> pageInfo = emsMoodService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param emsMood
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<EmsMood>> findList(@RequestBody(required = false)  EmsMood emsMood){
        //调用EmsMoodService实现条件查询EmsMood
        List<EmsMood> list = emsMoodService.findList(emsMood);
        return new Result<List<EmsMood>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用EmsMoodService实现根据主键删除
        emsMoodService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改EmsMood数据
     * @param emsMood
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  EmsMood emsMood,@PathVariable Integer id){
        //设置主键值
        emsMood.setId(id);
        //调用EmsMoodService实现修改EmsMood
        emsMoodService.update(emsMood);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增EmsMood数据
     * @param emsMood
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   EmsMood emsMood){
        //调用EmsMoodService实现添加EmsMood
        emsMoodService.add(emsMood);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询EmsMood数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<EmsMood> findById(@PathVariable Integer id){
        //调用EmsMoodService实现根据主键查询EmsMood
        EmsMood emsMood = emsMoodService.findById(id);
        return new Result<EmsMood>(true,StatusCode.OK,"查询成功",emsMood);
    }

    /***
     * 查询EmsMood全部数据
     * @return
     */
    @GetMapping
    public Result<List<EmsMood>> findAll(){
        //调用EmsMoodService实现查询所有EmsMood
        List<EmsMood> list = emsMoodService.findAll();
        return new Result<List<EmsMood>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
